<template>
  <div>
    <!-- 编辑性别 -->
    <!-- 选择器 -->
    <van-picker title="修改性别" show-toolbar :columns="columns" @cancel="$emit('close')" @confirm="onConfirm"
      :default-index='value' />
  </div>
</template>

<script>
// 修改用户性别请求
import { setUserProfile } from '@/api/user.js'
export default {
  data () {
    return {
      // 选择器内容
      columns: ['男', '女']
    }
  },
  props: {
    // 父传子性别
    value: {
      type: Number,
      required: true
    }
  },
  methods: {
    // 点击确认按钮
    async onConfirm (val, index) {
      // 加载中显示
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true,
        duration: 0
      })
      try {
        await setUserProfile({
          gender: index
        })
        this.$toast('修改成功')
        this.$emit('close')
        this.$emit('input', index)
      } catch (err) {
        this.$toast('修改失败')
      }
    }
  },
  computed: {},
  watch: {},
  filters: {},
  components: {},
  created () { },
  mounted () { }
}
</script>

<style scoped lang='less'>
</style>
